import aiml
import os

class alice_bot(aiml.Kernel):
    def __init__(self):
        aiml.Kernel.__init__(self)
        AIML_SET = os.path.join(os.path.dirname(__file__), 'alice')

        if os.path.isfile("bot_brain.brn"):
            self.bootstrap(brainFile="bot_brain.brn")
        else:
            # kernel.bootstrap(learnFiles="startup.xml", commands="LOAD ALICE")
            for file in os.listdir(AIML_SET):
                if file[-4::] == "aiml":
                    self.learn(os.path.join(AIML_SET, file))
            self.saveBrain("bot_brain.brn")
if __name__ == '__main__':
    alice = alice_bot()
    # Press CTRL-C to break this loop
    while True:
        message = input("Enter your message to the bot: ")
        if message == "quit":
            exit()
        elif message == "save":
            alice.saveBrain("bot_brain.brn")
        else:
            bot_response = alice.respond(message)
            # Do something with bot_response

